<%-- 
    Document   : incentive
    Created on : Apr 6, 2011, 3:37:32 PM
    Author     : Dine
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>

<html>
    <head>
        <sj:head jqueryui="true" jquerytheme="south-street" compressed="false"/>
        <jsp:include page="WEB-INF/fragments/globalHead.html"/>
        <title>Cashmate <s:property value="#session.branch.branchname"/> - Incentives</title>
        <style type="text/css">
            div#formResult > p{
                font-size: 12px;
            }
            div#theContent{
                width:990px;
                overflow:auto;
                margin:auto;
                height:500px;
            }
            div#gridOptsContainer{
                width:800px;
                margin:auto;
                text-align: center;
            }
            div.ui-jqgrid{
                margin:auto;
            }
            span.ui-jqgrid-title{
                font-size: 20px;
                text-align: center;
                margin: auto;
            }
            .ui-jqgrid-btable{
                font-size:12px !important;
            }
            .ui-jqgrid-htable{
                font-size:14px !important;
            }
            div.ui-jqdialog{
                max-height: 400px !important;
                width: 450px !important;
                overflow:auto !important; 
            }
        </style> <!--performance.jsp css-->
        <script type="text/javascript">
            var exist = false;
            $(document).ready(function(){
                $(window).unload(function(){
                    if(exist){
                        $.ajax({
                            type: "POST",
                            async:false,
                            url: "Cashmate/cancel-incentive",
                            context: document.body,
                            success:function(msg){
                                exist=false;
                                return false;
                            }
                        })
                    }
                });
            })
            
            $.subscribe("cancelIncentiveSubmitClick",function(event,data){
                $('#incentiveDialog').dialog('close');
            });
            
            $.subscribe("incentiveSubmitBefore",function(event,data){
                $('.dialogButton, #chooseIncentive').fadeOut();
            });

            $.subscribe("incentiveGridComplete",function(event,data){
                $('#incentiveIncentGrid_search').button( "option", "disabled", false );
            });
            
            $.subscribe('monthSelectComplete', function(event,data) {
                var s = $("#monthSelect").attr("value");
                if(s == "-1"){
                    $('div#formResult').removeClass("ui-state-highlight");
                    $('div#formResult').addClass("ui-state-error");
                    $('div#formResult').html(error('Sorry.There are <strong>no available Daily Cash Collection Report(s)</strong> to compute.'));
                    $('#incentiveSubmitButton').button( "option", "disabled", true );
                }
            });
        </script> <!--performance.jsp script-->
    </head>
    <body>
        <!--  JAVASCRIPT/SESSION FILTER      -->
        <jsp:include page="WEB-INF/fragments/filters.jsp"/>

        <!--  PRIVILEGE FILTER      -->
        <s:set name="status">${param.status}</s:set>
        <s:if test="%{#session.branch.branchid == 1}">
            <s:action name="query-privilege2" var="privilege1" executeResult="false">
                <s:param name="pagename" value="incentive.jsp"/>
                <s:param name="moduleid" value="14"/>
            </s:action>
            <s:if test='%{!#privilege1.viewable && #status != "nonviewable"}'>
                <script type="text/javascript">
                    window.location.href = "incentive.jsp?status="+escape("nonviewable");
                </script>
            </s:if>
            <s:elseif test="%{!#privilege1.viewable && #parameters.status == null}">
                <script type="text/javascript">
                    window.location.href = "incentive.jsp?status="+escape("nonviewable");
                </script>
            </s:elseif>
        </s:if>
        <s:else>
            <s:action name="query-privilege2" var="privilege2" executeResult="false">
                <s:param name="pagename" value="incentive.jsp"/>
                <s:param name="moduleid" value="12"/>
            </s:action>
            <s:if test='%{!#privilege2.viewable && #status != "nonviewable"}'>
                <script type="text/javascript">
                    window.location.href = "incentive.jsp?status="+escape("nonviewable");
                </script>
            </s:if>
            <s:elseif test="%{!#privilege2.viewable && #parameters.status == null}">
                <script type="text/javascript">
                    window.location.href = "incentive.jsp?status="+escape("nonviewable");
                </script>
            </s:elseif>
        </s:else>

        <!--  BRANCH FILTER      -->
        <s:if test="%{#session.branch.branchid != 1 && #parameters.branch != null}">
            <s:set name="b" value="%{#session.branch.branchid}"/>
            <s:set name="br">${param.branch}</s:set>
            <s:if test="%{#br != #b}">
                <script type="text/javascript">
                    window.location.href = "monthperformance.jsp?status="+escape("notbranch");
                </script>
            </s:if>
        </s:if>

        <s:div id="bodyContainer">
            <s:div id="logoContainer" cssClass="ui-widget-content ui-corner-all">
                <s:include value="WEB-INF/fragments/banner.jsp">
                    <s:param name="branch" value="#session.branch.branchname" />
                </s:include>
            </s:div>
            <jsp:include page="WEB-INF/fragments/top.jsp"/>
            <jsp:include page="WEB-INF/fragments/mainMenu.jsp?menu=Reports"/>
            <jsp:include page="WEB-INF/fragments/left.jsp?type=report"/>
            <s:div id="contentContainer" cssClass="ui-widget-content ui-corner-all">
                <h1 id="contentHeader" style="text-align:center;" class="ui-state-default ui-corner-all"><span id="level1">Incentives</span></h1>
                <s:div id="theContent">
                    <s:if test='%{#status == "nonviewable"}'>
                        <s:include value="WEB-INF/error/unauthorized.html"/>
                    </s:if>
                    <s:else>
                        <s:if test='%{#status == "notbranch"}'>
                            <h3 style="text-align: center;">Sorry. You don't belong to this branch.</h3>
                        </s:if>
                        <s:else>
                            <sj:dialog autoOpen="false" closeOnEscape="false" modal="true" id="incentiveDialog" title="Choose Monthly Incentive" width="500" showEffect="slide" openTopics="dialogopen" hideEffect="none">
                                <div id="formResult" class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;">
                                    <p style="text-align:center;"><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                                        Please <strong>select a month to display incentive computation.</strong>
                                    </p>
                                </div>
                                <s:form action="choose-incentive" cssStyle="margin:auto;" id="chooseIncentive">
                                    <s:url id="monthurl" action="select-month"/>
                                    <sj:select
                                        onCompleteTopics="monthSelectComplete"
                                        label="Month"
                                        href="%{monthurl}"
                                        id="monthSelect"
                                        name="monthandbranch"
                                        list="monthMap"
                                        />
                                </s:form>
                                <p style="text-align:center;margin:3px 0px;">
                                    <img id="indicator" src="res/sandbox/ajax-loader.gif" alt="Loading..." style="margin:auto;display:none"/>
                                </p>
                                <hr />
                                <sj:a cssClass="dialogButton ui-state-default" id="incentiveCancelButton"
                                      cssStyle="float:right;font-size:14px;"
                                      button="true"
                                      onClickTopics="cancelIncentiveSubmitClick">
                                    Cancel</sj:a>
                                <sj:submit cssClass="dialogButton ui-state-default" id="incentiveSubmitButton"
                                           cssStyle="float:right;font-size:14px;"
                                           button="true"
                                           effect="highlight"
                                           onBeforeTopics="incentiveSubmitBefore"
                                           targets="formResult"
                                           formIds="chooseIncentive"
                                           indicator="indicator"
                                           effectDuration="300"/>
                            </sj:dialog>

                            <s:div id="gridOptsContainer">
                                <%-- <s:if test="%{#session.incentiveList != null && #session.overallTotal != null}">
                                     <sj:submit button="true" 
                                                cssStyle="font-size:14px;" 
                                                disabled="true"
                                                id="incentiveIncentGrid_search" 
                                                onClickTopics="searchIncentiveGrid"
                                                value="Search Incentive Performance"/>
                                     
                                                                     <sj:submit button="true" 
                                                                                cssStyle="font-size:14px;" 
                                                                                disabled="true"
                                                                                id="weekPerfGrid_showhide" 
                                                                                onClickTopics="showHideCols"
                                                                                value="Show/Hide Columns"/>
                                     
                                 </s:if>--%>

                                <sj:submit button="true"
                                           cssStyle="font-size:14px;" 
                                           openDialog="incentiveDialog"
                                           value="Choose Incentive Computation"
                                           />
                            </s:div>
                            <hr />
                            <s:if test="%{#session.incentiveList != null}">
                                <script type="text/javascript">
                                    exist = true;
                                </script>
                                <s:bean name="com.cashmate.utilities.DCCRDate" var="date">
                                    <s:param name="date" value="%{#parameters.month}"/>
                                </s:bean>
                                <s:action name="select-branches" executeResult="false" var="br">
                                    <s:param name="forPerf" value="%{#parameters.branch}"/>
                                </s:action>
                                <s:url action="grid-incentives" id="remoteurl"/>
                                <sjg:grid
                                    id="incentiveGrid"
                                    caption="%{#br.branchname} Incentive Computation for %{#date.monthname} %{#parameters.year}"
                                    dataType="json"
                                    href="%{remoteurl}"
                                    gridModel="gridModel"
                                    pagerButtons="false"
                                    pagerInput="false"
                                    rowNum="-1"
                                    loadingText="Requesting Data..."
                                    width="930"
                                    shrinkToFit="true"
                                    pager="true"
                                    hoverrows="true"
                                    rownumbers="true"
                                    autoencode="true"
                                    viewrecords="true"
                                    navigator="true"
                                    navigatorAdd="false"
                                    navigatorDelete="false"
                                    navigatorEdit="false"
                                    navigatorSearch="false"
                                    navigatorView="true"
                                    onGridCompleteTopics="incentiveGridComplete"
                                    >

                                    <sjg:gridColumn name="areacode"
                                                    index="areacode"
                                                    title="Area"
                                                    searchoptions="{sopt:['eq']}"
                                                    sortable="false"
                                                    search="false"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="cc"
                                                    index="cc"
                                                    title="CC"
                                                    searchoptions="{sopt:['eq']}"
                                                    sortable="false"
                                                    search="false"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="rate_s"
                                                    index="rate_s"
                                                    title="Rate"
                                                    sortable="false"
                                                    search="false"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="gross"
                                                    index="gross"
                                                    title="Gross"
                                                    sortable="false"
                                                    search="false"
                                                    formatter="currency"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="officeShare"
                                                    index="officeShare"
                                                    title="Office Share"
                                                    sortable="false"
                                                    search="false"
                                                    formatter="currency"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="projIncentive"
                                                    index="projIncentive"
                                                    title="Proj. Incentive"
                                                    sortable="false"
                                                    search="false"
                                                    formatter="currency"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="sales"
                                                    index="sales"
                                                    title="Sales"
                                                    sortable="false"
                                                    search="false"
                                                    formatter="currency"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="actIncentive"
                                                    index="actIncentive"
                                                    title="Act. Incentive"
                                                    sortable="false"
                                                    search="false"
                                                    formatter="currency"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="payableIncentive"
                                                    index="payableIncentive"
                                                    title="Payable Incentive"
                                                    sortable="false"
                                                    search="false"
                                                    formatter="currency"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="penalty"
                                                    index="penalty"
                                                    title="Penalty"
                                                    sortable="false"
                                                    search="false"
                                                    formatter="currency"
                                                    align="center"
                                                    />

                                    <sjg:gridColumn name="nm"
                                                    index="nm"
                                                    title="NM"
                                                    sortable="false"
                                                    search="false"
                                                    formatter="currency"
                                                    align="center"
                                                    />
                                </sjg:grid>
                            </s:if>
                        </s:else>
                    </s:else>
                </s:div>
            </s:div>
            <jsp:include page="WEB-INF/fragments/bottom.jsp"/>
        </s:div>
    </body>
</html>
